from apis.bzy import Bzy


class Channel(Bzy):
    def create_channel(self, name):
        """
        创建渠道
        :param name:渠道名称
        :return:响应体
        """
        create_url = f"{self.base_url}/v1/wxorderchannel"
        json = {"name": name,
                "manager": "wxid_9izu0ybeqnb622",
                "wxGroupNickname": "特工小队",
                "wxReceiveNickname": "！"}
        req = {
            "method": "POST",
            "url": create_url,
            "json": json,
            "headers": {
                "Authorization": self.token
            }
        }
        r = self.send_api(req)
        return r

    def search_channel(self, name):
        """
        搜索渠道
        :param name: 渠道名称
        :return: 响应体
        """
        search_url = f"{self.base_url}/v1/wxorderchannel/"
        req = {
            "method": "GET",
            "url": search_url,
            "params": {
                "name": name
            },
            "headers": {
                "Authorization": self.token
            }
        }
        r = self.send_api(req)
        return r

    def update_channel(self, new_name, id):
        update_url = f"{self.base_url}/v1/wxorderchannel/{id}"
        req = {
            "method": "PUT",
            "url": update_url,
            "json": {
                "name": new_name,
                "logisticsTrackStatus": 0
            },
            "headers": {
                "Authorization": self.token
            }
        }
        r = self.send_api(req)
        return r

    def del_channel(self, id):
        """
        删除渠道
        :param id: 渠道id
        :return: 响应体
        """
        del_url = f"{self.base_url}/v1/wxorderchannel/{id}"
        req = {
            "method": "DELETE",
            "url": del_url,
            "headers": {
                "Authorization": self.token
            }
        }
        r = self.send_api(req)
        return r
